//
// Created by 66477 on 2022/9/28.
//

#ifndef DATA_STRUCTURE_STACK4_2_H
#define DATA_STRUCTURE_STACK4_2_H

#include "Node4_2.h"
#include <cstring>

class Stack4_2 {
private:
    Node4_2 *top = new Node4_2();
    Node4_2 *base = top;
public:
    string Analysis(string s) {
        for (int i = 0; i < s.length(); ++i) {
            if (s[i] == '(') {
                push('(');
            } else if (s[i] == ')') {
                if (pop() != '(') {
                    return "false";
                }
            }
        }
        if (top == base) {
            return "ture";
        } else {
            return "false";
        }

    }

    void push(char x) {
        Node4_2 *n = new Node4_2(x);
        n->setNext(top);
        top = n;
    }

    char pop() {
        Node4_2 *p = top;
        top = top->getNext();
        char c = p->getData();
        delete p;
        return c;
    }
};

#endif //DATA_STRUCTURE_STACK4_2_H
